package is.server.controller;

import is.common.interfaces.mvc.Controller;
import is.server.Locale;
import is.server.controller.session.local.command.OpenCommand;
import is.server.model.ServerModel;
import is.server.ui.Cli;

import javax.xml.transform.TransformerException;
import java.io.IOException;

/**
 * @author aspr0
 *         Date: 01.04.12
 *         Time: 5:31
 */
public class ServerController implements Controller
{
    private ServerModel model;
    private Cli userInterface;

    public ServerModel getModel()
    {
        return model;
    }

    public Cli getUserInterface()
    {
        return userInterface;
    }

    public ServerController()
    {
        model = new ServerModel();
        userInterface = new Cli();
    }

    public void activate(String... params)
    {
        /* trying to activate model */
        new OpenCommand(params).execute();

        userInterface.activate();
    }

    public void deactivate()
    {
        userInterface.exposeInfoMsg(Locale.INFO_STOPPING_SERVER);

        try
        {
            model.deactivate();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch (TransformerException e)
        {
            e.printStackTrace();
        }
        userInterface.deactivate();
    }
}
